/*
*
==============================================================================
*  Name        : 
*  Part of     : Omen Game Engine
*  Description : 
*  Version     : 1.0
*
*  Copyright (c) 2013 Lauri Kortevaara.
* 
==============================================================================
*/

#define OMEN_SOURCE 1

#include <OmenAABB.h>

using namespace Omen;

/// <summary>Axis Aligned Bounding Box class</summary>
AABB::AABB( const Omen::Vector3d& min, const Omen::Vector3d& max ) :
    m_minimum(min),
    m_maximum(max)
{
}

/// <summary>Copy constructor</summary>
AABB::AABB( const AABB& other ) :
    m_minimum(other.m_minimum),
    m_maximum(other.m_maximum)
{
}

/// <summary>Destructor of AABB</summary>
AABB::~AABB()
{
}

/// <summary>Returns the minimum coordinate of AABB in 3d-space</summary>
const Omen::Vector3d& AABB::minimum() const
{
    return m_minimum;
}

/// <summary>Returns the maximum coordinate of AABB in 3d-space </summary>
const Omen::Vector3d& AABB::maximum() const
{
    return m_maximum;
}

/// <summary>Sets the minimum coordinate of the AABB</summary>
void AABB::setMinimum( const Omen::Vector3d& minimum ) 
{
    m_minimum = minimum;
}

/// <summary>Sets the maximum coordinate of the AABB</summary>
void AABB::setMaximum( const Omen::Vector3d& maximum ) 
{
    m_maximum = maximum;
}

/// <summary>Returns the width of the bounding box</summary>
Omen::Float AABB::width() const
{
    return (m_maximum.x - m_minimum.x);
}
    
/// <summary>Returns the height of the bounding box</summary>
Omen::Float AABB::height() const
{
    return (m_maximum.y - m_minimum.y);
}

/// <summary>Returns the depth of the bounding box</summary>
Omen::Float AABB::depth() const
{
    return (m_maximum.z - m_minimum.z);
}

/// <summary>Returns a union of this and given AABBs</summary>
Omen::AABB AABB::operator+( const Omen::AABB& other )
{
    Omen::Float minX, minY, minZ;
    Omen::Float maxX, maxY, maxZ;

    minX = minY = minZ = 1.0e10;
    maxX = maxY = maxZ = -1.0e10;

    minX = min( minX, m_minimum.x ); minX = min( minX, other.m_minimum.x );
    minY = min( minY, m_minimum.y ); minY = min( minY, other.m_minimum.y );
    minZ = min( minZ, m_minimum.z ); minZ = min( minZ, other.m_minimum.z );

    maxX = max( maxX, m_maximum.x ); maxX = max( maxX, other.m_maximum.x );
    maxY = max( maxY, m_maximum.y ); maxY = max( maxY, other.m_maximum.y );
    maxZ = max( maxZ, m_maximum.z ); maxZ = max( maxZ, other.m_maximum.z );

    return AABB(Vector3d(minX,minY,minZ), Vector3d(maxX,maxY,maxZ));
}

/// EOF 